<template>
  <el-dialog
    title="等级奖励"
    v-model="dialogVisible"
    @close="dialogFormVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="600px"
  >
    <el-form size="" ref="formRef" :model="form" label-width="250px">
      <el-form-item label="佣金类型：">
        <el-radio-group v-model="form.agent_money_type">
          <el-radio :value="10">百分比</el-radio>
          <el-radio :value="20">固定金额</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="一级分销奖励">
        <el-input v-model="form.first_money" class="max-w460"
          ><template #suffix>{{
            form.agent_money_type == 10 ? "%" : "元"
          }}</template></el-input
        >
      </el-form-item>
      <el-form-item label="二级分销奖励">
        <el-input v-model="form.second_money" class="max-w460"
          ><template #suffix>{{
            form.agent_money_type == 10 ? "%" : "元"
          }}</template></el-input
        >
      </el-form-item>
      <el-form-item label="三级分销奖励">
        <el-input v-model="form.third_money" class="max-w460"
          ><template #suffix>{{
            form.agent_money_type == 10 ? "%" : "元"
          }}</template></el-input
        >
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible">取 消</el-button>
      <el-button type="primary" @click="saveAward()" :disabled="submit_loading"
        >确 定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import { addgrade, getGradeAgent, saveGradeAgent } from "@/api/user.js";
export default {
  data() {
    return {
      form: {
        grade_id: 0,
        agent_money_type: 10,
        first_money: 0,
        second_money: 0,
        third_money: 0,
      },
      /*左边长度*/
      formLabelWidth: "120px",
      /*是否显示*/
      dialogVisible: false,
      /*是否正在提交*/
      submit_loading: false,
    };
  },
  props: ["open_award", "grade_id"],
  created() {
    this.dialogVisible = this.open_award;
    //获取奖励设置
    getGradeAgent({
      grade_id: this.grade_id,
    }).then((data) => {
      if (data.data) {
        this.form = data.data;
      }
      this.form.grade_id = this.grade_id;
      console.log(data, this.form);
    });
  },
  methods: {
    /*添加等级*/
    saveAward() {
      let self = this;
      let params = this.form;
      saveGradeAgent(params).then((res) => {
        self.submit_loading = false;
        ElMessage({
          message: res.msg,
          type: "success",
        });
        console.log("1111");
        self.dialogFormVisible(true);
      });
    },
    /*关闭弹窗*/
    dialogFormVisible(e) {
      console.log(e);
      if (e) {
        console.log("关闭弹窗");
        this.$emit("closeDialog", {
          type: "success",
          openDialog: false,
        });
      } else {
        this.$emit("closeDialog", {
          type: "error",
          openDialog: false,
        });
      }
    },
  },
};
</script>

<style></style>
